//
//  SHUserPerfenceTool.m
//  Netease
//
//  Created by 王方伟 on 2017/8/21.
//  Copyright © 2017年 wfw. All rights reserved.
//

#import "SHUserPerfenceTool.h"

#define kUserPerfenceUtilFile [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)lastObject] stringByAppendingPathComponent:@"account.data"]

@implementation SHUserPerfenceTool

+ (instancetype)sharedUserPerfence{
    static SHUserPerfenceTool *userPerfence;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        userPerfence = [[SHUserPerfenceTool alloc] init];
    });
    return userPerfence;
}

#pragma mark 保存用户消息
- (void)saveAccount:(SHAccount*)account{
    if (!account) {
        [NSKeyedArchiver archiveRootObject:account toFile:kUserPerfenceUtilFile];
        return;
    }
    [NSKeyedArchiver archiveRootObject:account toFile:kUserPerfenceUtilFile];
}

#pragma 获取用户消息
- (SHAccount *)account{
    SHAccount *user = [NSKeyedUnarchiver unarchiveObjectWithFile:kUserPerfenceUtilFile];
    if (!user) return nil;
    return user;
}
@end
